package com.ljfresh.customer.controller;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import com.ljfresh.customer.utils.FileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;

/**
 * @author: Lucifer
 * @time: 2020/4/14-10:23
 */
@Api(tags = "公共模块",description = "公共模块")
@CrossOrigin
@RestController
@RequestMapping("/common")
public class CommonController {

    @ApiOperation(value = "文件上传", notes = "文件上传")
    @PostMapping("/upload")
    public Map<String, Object> upload(@RequestParam("file") MultipartFile[] files, HttpServletRequest request){//@RequestParam("file") postman上传不成功 @RequstBody 前端上传不成功
        //可以在上传文件的同时接收其它参数
        Map<String, Object> map = Maps.newConcurrentMap();
        try {
            map = FileUtils.ossfileUploadNotRename(files, request);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    }
}
